﻿using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;

namespace DB.SchemaSync.Library.Models
{
	/// <summary>
	/// Encapsulates source and destination Databases as well as the SchemaComparison result of a comparison.
	/// Used to generate test cases for SchemaSync repo
	/// </summary>
	public class TestCase
	{
		public Database Source { get; set; }
		public Database Destination { get; set; }
		public HashSet<ExcludeObject> ExcludeObjects { get; set; }

		public IEnumerable<DbObject> Create { get; set; }
		public IEnumerable<AlteredObject> Alter { get; set; }
		public IEnumerable<DbObject> Drop { get; set; }

		public void Save(string fileName)
		{
			string json = JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings()
			{
				PreserveReferencesHandling = PreserveReferencesHandling.All
			});
			File.WriteAllText(fileName, json);
		}
	}
}